﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Douban.Api.Infrastructure
{
    [AttributeUsage(AttributeTargets.Property, Inherited = true)]
    public class ElementAttribute : Attribute
    {
        public string ElementName { get; set; } 
        public string Namespace { get; set; }

        public ElementAttribute(string elementName) : this(elementName, NsManager.Default) {}

        public ElementAttribute(string elementName, string ns)
        {
            ElementName = elementName;
            Namespace = ns;
        }

        public virtual string GetXPath(XmlNamespaceManager nsManager)
        {
            return string.Format("{0}:{1}", nsManager.LookupPrefix(Namespace), ElementName);
        }
    }
}
